package com.gams.springboot.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.gams.springboot.pojo.Quota;
import com.gams.springboot.services.QuotaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;


@Component
@Scope("prototype")
public class QuotaListener extends AnalysisEventListener<Quota> {

    @Autowired
    private QuotaService quotaService;

    private final Integer MAX_LIST_SIZE=5;

    List<Quota> list=new ArrayList<Quota>();

    /**
     * @param data
     * @param context
     */
    @Override
    public void invoke(Quota data, AnalysisContext context) {
        list.add(data);
        if (list.size()%MAX_LIST_SIZE==0){
            quotaService.readExcel(list);
            list.clear();
        }
    }



    /**
     * 读取文档后调用的方法
     * @param context
     */
    @Override
    public void doAfterAllAnalysed(AnalysisContext context) {

    }
}
